home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revolution - Das Atari CD Magazin 1997
/
Revolution - Das Atari CD Magazin 1.iso
/
software
/
anwendng
/
qed_397
/
sourcen
/
menu.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-14
|
13KB
|
616 lines
#include <errno.h>
#include "global.h"
#include "av.h"
#include "block.h"
#include "clipbrd.h"
#include "desktop.h"
#include "disk.h"
#include "edit.h"
#include "error.h"
#include "file.h"
#include "find.h"
#include "fontsel.h"
#include "icon.h"
#include "kurzel.h"
#include "makro.h"
#include "obj.h"
#include "options.h"
#include "projekt.h"
#include "rsc.h"
#include "se.h"
#include "scroll.h"
#include "set.h"
#include "text.h"
#include "umbruch.h"
#include "windows.h"
#include "menu.h"
/****** VARIABLES ************************************************************/
/* Menuenummer zu einer Aktion */
WORD menu_nr[] = {MUNDO, MCUT, MCOPY, MPASTE, MCLEAR, MSELALL,
MCLOSE, -1, MOPEN, MINFO, -1, MLEFT, MRIGHT,
MFORMAT, MPRINT, MABAND, MSAVE, MSAVENEW, MFIND,
MFNDGOON, MADD, -1, MGOTO, MSCUT, -1, -1,
MSTAB2LZ, -1, MSLZ2TAB, -1, MZEICHEN, MSWAP,
MLEFT, MRIGHT, MSMALL, MBIG, MSMALLBIG, MCAPS,
-1, -1, MUMLAUTE, -1, MFEHLERSPRUNG};
/*****************************************************************************/
LOCAL WORD menu_width;
LOCAL VOID mclearup (VOID);
/*****************************************************************************/
VOID set_overwrite(BOOLEAN over)
{
if (overwrite && !over) /* einfügen */
{
overwrite = FALSE;
menu_icheck(menu, MOOVERW, FALSE);
menu_icheck(menu, MOEINF, TRUE);
}
else /* überschreiben */
{
overwrite = TRUE;
menu_icheck(menu, MOOVERW, TRUE);
menu_icheck(menu, MOEINF, FALSE);
}
}
/***************************************************************************/
BOOLEAN menu_key(MKINFO *mk)
{
WORD title, item, kreturn, kstate;
updt_menu();
if (mk->shift) /* eventuelle SHIFT-Tasten ausblenden */
{
global_shift = TRUE;
mk->shift = FALSE;
kstate = mk->kstate;
mk->kstate &= ~3;
kreturn = mk->kreturn;
mk->kreturn &= ~NKF_SHIFT;
}
if (my_menu_key (menu, mk, &title, &item))
{
hndl_menu(title, item, FALSE); /* Menü aufrufen */
return (TRUE); /* fertig */
}
if (global_shift) /* und wieder einblenden */
{
mk->shift = TRUE;
mk->kstate = kstate;
mk->kreturn = kreturn;
}
return (FALSE);
} /* menu_key */
LOCAL VOID multitest_action(SET icons, SET action)
{
WORD icp[MAX_ICON_ANZ], ic;
SET help;
WORD i;
i = all_icons(icp);
setclr(action);
while ((--i)>=0)
{
ic = icp[i];
if(setin(icons,ic))
{
Icon_exist(ic,help);
setor(action,help);
}
}
}
GLOBAL VOID set_menu(WORD item, BOOLEAN yes)
{
if (((menu[item].ob_state & DISABLED) == 0) != yes)
menu_ienable (menu, item, yes);
}
GLOBAL VOID mark_menu(WORD item, BOOLEAN yes)
{
if (((menu[item].ob_state & CHECKED) != 0) != yes)
menu_icheck (menu, item, yes);
}
GLOBAL VOID fillup_menu (WORD item, CONST UBYTE *new_text, WORD free)
{
WORD len, max_len;
UBYTE *str;
str = menu[item].ob_spec.free_string + free;
len = (short) strlen(new_text);
max_len = (short) strlen(str) - 4; /* ' ?? ' Shortcut nicht überscrieben! */
if (len > max_len)
len = max_len;
str = COPYB(str, new_text, len);
len = max_len - len; /* Restlänge */
while ((--len) >= 0)
*str++ = ' ';
}
LOCAL VOID set_MCOPY(char *n)
{
fillup_menu(MCOPY, n, 2);
set_menu(MCOPY, TRUE);
}
VOID updt_menu (VOID)
{
WINDP window;
SET all_actions;
BOOLEAN yes;
WORD i, nr;
setclr(all_actions);
window = top();
if (sel_window != NULL) /* Aktion für selektierte Objekte */
{
if (sel_window->class == DESK)
multitest_action(sel_objs,all_actions);
else
{
Icon_exist(sel_window->link+SUB_ICON,all_actions);
}
mark_menu(MSEL,FALSE);
set_menu(MSEL,FALSE);
set_menu(MSETMARK,FALSE);
}
else /* Aktionen für oberstes Fenster */
{
if (window!=NULL)
Icon_exist(window->link, all_actions);
else
Icon_exist(0,all_actions);
if (window!=NULL && window->class == CLASS_EDIT && !(window->flags & WI_ICONIFIED))
{
TEXTP t_ptr = get_text(window->link);
mark_menu(MSEL, (!ctrl_mark_mode && t_ptr->blk_mark_mode));
set_menu(MSEL, !ctrl_mark_mode);
set_menu(MSETMARK,TRUE);
}
else
{
mark_menu(MSEL,FALSE);
set_menu(MSEL,FALSE);
set_menu(MSETMARK,FALSE);
}
}
/* Desk + 2 Fenster || wind-global */
yes = ((num_windows(NIL,SRCH_OPENED)>=3) || wind_cycle);
set_menu(MCYCLE, yes);
mark_menu(MSRECORD, makro_rec);
for (i=DO_ANZ; (--i)>=0; )
{
nr = menu_nr[i];
if (nr > -1)
set_menu(nr,setin(all_actions,i));
}
if (setin(all_actions, DO_LINECOPY))
set_MCOPY(STRING(LCOPYSTR));
else if (setin(all_actions, DO_COPY))
set_MCOPY(STRING(COPYSTR));
setup_semenu(); /* -> comm.c */
} /* updt_menu */
/*
* Alle Menütitel abschalten, nur die ACC bleiben aktiv.
* Wird bei All-Iconify benutzt.
*/
#define THEBAR 1 /* Objekt-Nummer der Menüzeile */
#define THEACTIVE 2 /* Objekt-Nummer der aktiven Menüs */
#define THEFIRST 3 /* Objekt-Nummer des ersten Menüs */
VOID enable_menu(BOOLEAN enable)
{
WORD titel;
wind_update(BEG_UPDATE);
titel = menu[THEFIRST].ob_next;
while (titel != THEACTIVE)
{
disable_objc(menu, titel, !enable);
titel = menu[titel].ob_next;
}
if (enable)
menu[THEACTIVE].ob_width = menu_width;
else
{
if (menu[THEACTIVE].ob_width != menu[THEFIRST].ob_width)
{
menu_width = menu[THEACTIVE].ob_width;
menu[THEACTIVE].ob_width = menu[THEFIRST].ob_width;
}
}
/* About-Eintrag auch noch */
menu_ienable(menu, MABOUT, enable);
if (!aes41 || (menu_bar(NULL, -1) == gl_apid))
menu_bar(menu, TRUE);
wind_update(END_UPDATE);
} /* enable_menu */
/*****************************************************************************/
LOCAL VOID do_multi_action(WORD action)
{
WORD icp[MAX_ICON_ANZ], ic;
SET sel_icons;
WORD i, anz;
anz = all_icons(icp);
setcpy(sel_icons, sel_objs);
for (i=0; i<anz; i++) /* In dieser Reihenfolge! */
{
ic = icp[i];
if (setin (sel_icons, ic))
{
if (do_icon(ic,action)<0 && action==DO_OPEN)
{
note(1, NOWINDOW);
break;
}
}
}
}
VOID do_action(WORD action)
{
if (sel_window!=NULL)
{
if (sel_window->class == DESK)
do_multi_action(action);
else
{
if (do_icon(sel_window->link+SUB_ICON,action)<0 && action==DO_OPEN)
note(1, NOWINDOW);
}
}
else
{
WINDOWP w = top();
if (w!=NULL)
do_icon(w->link,action);
else
do_icon(0,action);
}
}
LOCAL VOID menu_help(WORD title, WORD item)
{
UBYTE help[128], *p1, str[128];
/* Spezial-Fälle: besonderer Text */
if (item >= MMARKE1 && item <= MMARKE5)
strcpy(str, STRING(HYPMARKESTR));
else if (item == MPROJEKT)
strcpy(str, STRING(DEFPRJSTR));
else if (title == MSHELL)
strcpy(str, "Shell");
else
{
/* Spezial-Fälle: Item ummappen */
if (item == MOEINF)
item = MOOVERW;
/* die führenden ' ' überspringen und das letzte auch nicht */
strcpy(help, menu[item].ob_spec.free_string);
strncpy(str, help + 2, (short) strlen(help) - 3);
p1 = strrchr(str, ' ');
while (*(p1--) == ' ') /* Leerzeichen weg */
;
*(p1+2) = EOS;
if (str[strlen(str) - 1] == '.') /* es folgen '...' */
str[strlen(str) - 3] = EOS;
}
if (str[0] != EOS)
call_hyp(str);
}
VOID hndl_menu (WORD title, WORD item, BOOLEAN ctrl)
{
WINDP w;
WORD action, antw, anz;
UBYTE str[10];
if (ctrl)
menu_help(title, item);
else
{
menu_tnormal(menu, title, FALSE); /* Titel invers darstellen */
action = -1;
switch (item)
{
case MABOUT :
info_desktop();
break;
/* ==== Datei ==== */
case MNEWTEXT :
new_edit();
break;
case MOPEN :
if (sel_window==NULL)
{
if (do_icon(idisk,DO_OPEN)<0)
note(1, NOWINDOW);
}
else
action = DO_OPEN;
break;
case MADD :
action = DO_ADD;
break;
case MNEWPROJ :
new_prj();
break;
case MCLOSE :
if (no_desktop)
action = DO_DESTRUCT;
else
action = DO_CLOSE;
break;
case MCLEAR :
action = DO_CLEAR;
break;
case MCYCLE :
if ((wind_cycle) && (send_avkey(4, 0x1117))) /* ^W */
break;
cycle_window();
break;
case MSAVE:
action = DO_SAVE;
break;
case MSAVENEW:
action = DO_SAVENEW;
break;
case MABAND :
action = DO_ABAND;
break;
case MPRINT :
action = DO_PRINT;
break;
case MINFO :
action = DO_INFO;
break;
case MQUIT2 :
quick_close = TRUE;
case MQUIT :
if (Icon_test(0,DO_DESTRUCT))
{
/* Fenster ist danach weg */
menu_tnormal(menu, title, TRUE);
Icon_edit(0,DO_DESTRUCT);
}
break;
/* ==== Bearbeiten ==== */
case MUNDO :
action = DO_UNDO;
break;
case MCUT :
action = DO_CUT;
break;
case MCOPY :
w = top();
if (w!=NULL && w->class==CLASS_EDIT)
{
TEXTP t_ptr = get_text(w->link);
if (t_ptr->block)
action = DO_COPY;
else
action = DO_LINECOPY;
}
break;
case MPASTE :
action = DO_PASTE;
break;
case MSEL :
w = top();
if (w!=NULL && w->class==CLASS_EDIT)
{
TEXTP t_ptr = get_text(w->link);
if (t_ptr->blk_mark_mode)
t_ptr->blk_mark_mode = FALSE;
else
{
blk_demark(t_ptr);
restore_edit();
blk_mark(t_ptr,0);
t_ptr->blk_mark_mode = TRUE;
}
}
break;
case MSELALL :
action = DO_SELALL;
break;
case MFORMAT :
action = DO_FORMAT;
break;
case MSWAP:
action = DO_SWAPCHAR;
break;
case MLEFT :
if (global_shift)
action = DO_ONE_LEFT;
else
action = DO_LEFT;
break;
case MRIGHT :
if (global_shift)
action = DO_ONE_RIGHT;
else
action = DO_RIGHT;
break;
case MSMALLBIG :
action = DO_CHNG_SMBG;
break;
case MBIG:
action = DO_SMALL2BIG;
break;
case MSMALL :
action = DO_BIG2SMALL;
break;
case MCAPS:
action = DO_CAPS;
break;
/* ==== Suchen ==== */
case MFIND :
if (global_shift)
do_icon(idisk, DO_FIND);
else
action = DO_FIND;
break;
case MFNDGOON:
action = DO_FINDNEXT;
break;
case MGOTO :
action = DO_GOTO;
break;
case MSETMARK:
w = top();
if (w!=NULL)
config_marken(get_text(w->link));
break;
case MMARKE1 :
case MMARKE2 :
case MMARKE3 :
case MMARKE4 :
case MMARKE5 :
goto_marke(item-MMARKE1);
break;
/* ==== Spezial ==== */
case MSRECORD:
if (makro_rec)
end_rec(TRUE);
else
start_rec();
break;
case MSPLAY :
anz = 1;
if (global_shift)
{
objc_setstring(makrorep, MREPANZ, "");
Arrow_mouse();
antw = HndlDial (makrorep, MREPANZ, FALSE, NULL, NULL);
Last_mouse();
if (antw == MREPOK)
{
objc_getstring(makrorep,MREPANZ,str);
anz = atoi(str);
}
else
break;
}
start_play(-1, anz);
break;
case MSMAKRO :
makro_dial();
break;
case MZEICHEN:
action = DO_ZEICHTAB;
break;
case MUMLAUTE:
action = DO_UMLAUT;
break;
case MFEHLER:
fehler_box();
break;
case MFEHLERSPRUNG:
action = DO_FEHLER;
break;
case MSCUT :
action = DO_CUTLINES;
break;
case MSTAB2LZ:
action = DO_TAB2LZ;
break;
case MSLZ2TAB:
action = DO_LZ2TAB;
break;
/* ==== Optionen ==== */
case MOEINF:
set_overwrite(FALSE);
break;
case MOOVERW:
set_overwrite(TRUE);
break;
case MSCLEAR :
clearup_dial();
break;
case MOFONT :
if (select_font(vdi_handle))
font_change();
break;
case MGLOBALO:
global_options();
break;
case MLOCALOP:
local_options();
break;
case MAUTOSAVE :
autosave_dial();
break;
case MPROJEKT :
open_def_prj();
break;
case MTAKEPRJ :
add_to_def();
break;
case MSOPTION:
antw = option_save(TRUE);
if (antw != 0)
{
if (antw == -ENOSPC)
{
UBYTE tmp[20];
make_shortpath(qed_path, tmp, 19);
snote(1, NOSPACE, tmp);
}
else
note(1, WRITEERR);
}
break;
/* ==== Shell ==== */
case MSOPT :
case MSQUIT :
case MSMAKEFILE :
case MSCOMP :
case MSMAKE :
case MSMAKEALL :
case MSLINK :
case MSEXEC :
case MSMAKEEXEC :
hndl_es(item);
default:
break;
}
if (action!=-1)
do_action(action);
} /* if ctrl */
menu_tnormal(menu, title, TRUE); /* Titel wieder normal */
} /* hndl_menu */